package com.fnst.caesar.util;

import java.io.*;
import java.util.*;

import javax.servlet.http.*;

import org.apache.poi.hssf.usermodel.*;

public class ExcelUtil
{
	public ExcelUtil()
	{
		
	}
	
	public static List<String[]> importExcel(String path, int col, int skip) throws Exception
	{
		List<String[]> result = new ArrayList<String[]>();
		InputStream is = new FileInputStream(path);
		HSSFWorkbook wb = new HSSFWorkbook(is);
		HSSFSheet sh = wb.getSheetAt(0);
		int rowNum = sh.getLastRowNum();
		for(int i = skip; i <= rowNum; i++)
		{
			HSSFRow row = sh.getRow(i);
			int cellNum = row.getLastCellNum();
			String[] content = new String[col];
			for(int j = 0; j < cellNum; j++)
			{
				HSSFCell cell = row.getCell(j);
				if(cell.getCellType() != HSSFCell.CELL_TYPE_NUMERIC)
				{
					HSSFRichTextString rts = cell.getRichStringCellValue();
					content[j] = rts.getString();
				}
				else
				{
					content[j] = Double.toString(cell.getNumericCellValue());	
				}
				result.add(content);
			}
		}
		
		return result;
	}
	
	public static String exportExcel(List result, String[] head, HttpServletRequest request)
	{
		String rootPath = request.getRealPath(File.separator);
		String userPath = "tmp" + File.separator;
		String fullPath = rootPath + userPath;
		File upDir = new File(fullPath);
		if (!upDir.exists())
		{
			upDir.mkdirs();
		}
		
		int width = 2560;
		short height = 500;
		
	}
}
